package com.example.core.shiroLogin;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName MyExceptionResolver
 * @Author zhangzhaoyang
 * @Date 2019/10/17 15:32
 * 用spring mvc的统一异常处理类HandlerExceptionResolver
 * 定义一个类继承HandlerExceptionResolver，然后判断UnauthorizedException异常即可
 **/
public class MyExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        if (e instanceof UnauthorizedException) {
            ModelAndView mv = new ModelAndView("/403");
            return mv;
        }
        return null;
    }

}
